/*
 * @Author: your name
 * @Date: 2022-04-24 20:04:31
 * @LastEditTime: 2022-04-24 22:08:40
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /safe_transmission_platform/src/tcpServer.h
 */
#ifndef __DANIEL_TCPSERVER_H__
#define __DANIEL_TCPSERVER_H__

#include <string>
#include <memory>
#include "tcpSocket.h"
#include "config.h"
namespace daniel
{
    struct ServerDefine
    {
        ServerDefine(){};
        ServerDefine(const std::string& ipVar, uint16_t portVar):ip(ipVar),port(portVar){}
        std::string ip;
        uint16_t port;
    };
    class TcpServer
    {
    public:
        using ptr=std::shared_ptr<TcpServer>;
        TcpServer()
        {};
        TcpServer(uint16_t port,const std::string& ip="");
        TcpServer(const ServerDefine& serverDefine);
        void init(uint16_t port,const std::string& ip="");
        ~TcpServer();
        //输入等待的ms数
        TcpSocket* acceptConnfd(int timeout=1000);
        std::string getIP() const {return m_ip;}
        uint16_t getPort() const {return m_port;}
        void disconnect();
    private:
        int32_t m_lfd;
        std::string m_ip;
        uint16_t m_port;
    };
} // namespace daniel

#endif